package cn.learn.druid;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * 主数据源，多数据源的时候，建立多个
 *
 * @author huangyezhan
 * @date 2020年02月17日14:32
 */
@Configuration
public class MasterDataSourceConfig {

    /**
     * 用在方法上的@ConfigurationProperties，必须要跟@Bean同时配合使用
     *
     * @return
     */
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.druid")
    public DataSource druidDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        //dataSource.setStatLogger(new MyStatLogger());
        //dataSource.setTimeBetweenLogStatsMillis(60 * 1000);
        return dataSource;
    }


}
